package com.simon.webflux.filter;

import org.springframework.boot.web.reactive.filter.OrderedWebFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Component
public class TestFilter implements OrderedWebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        // System.out.println("into test filter...");
        return chain.filter(exchange)
                .doOnError(err -> System.out.println("err = " + err))
                .doFinally(signalType -> {
                    // System.out.println("out test filter... signalType = " + signalType)
                });
    }

    @Override
    public int getOrder() {
        return OrderedWebFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER;
    }
}
